var http = require('http');
var fs = require('fs');
var path = require('path')//nodejs的自带模块获得后缀名字
var url =require('url');
var mime = require('./module.js');

 http.createServer(function(request,response){
	var pathname = url.parse(request.url).pathname;//解析
	var extname = path.extname(pathname);//获取后缀
	var mine = mime.getName(extname);//根据后缀返回头
	if(pathname=='/'){
		pathname='/login.html';//默认加载首页
	}
	if(pathname != '/favicon.ico'){
		//读取index.html
		fs.readFile(__dirname+pathname,function(err,result){
			if(err){
				console.log('404');
				return;
			}else{ //有文件
				response.writeHead(200,{"Content-Type":""+mine+";charset='UTF-8'"});
				//请求头
				response.write(result);
				response.end();
			}
		});
	}

	
 }).listen(8080);
